package com.pj.lib.aura.utils;



import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class TitleBar {
	Activity mActivity;
	
	TextView textViewTitle;
	ProgressBar progressBarTitle;
	ImageView imageViewTitleGoodConnection;
	ImageView imageViewTitleBadConnection;
	
	public static final int CONNECTED = 1;
	public static final int CONNECTING = 2;
	public static final int NOT_CONNECTED = 3;
	
	
	
	public TitleBar(Activity activity, String titleName, int titleBarLayout) {
		this.mActivity = activity;
	
		activity.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				titleBarLayout);
		
		textViewTitle = (TextView) activity.findViewById(com.pj.aura.R.id.lib_title_bar_text);
		textViewTitle.setText(titleName);

		progressBarTitle = (ProgressBar) activity.findViewById(com.pj.aura.R.id.lib_title_bar_progress_bar);
		imageViewTitleGoodConnection = (ImageView) activity.findViewById(com.pj.aura.R.id.lib_title_bar_connection_status_good);
		imageViewTitleBadConnection = (ImageView) activity.findViewById(com.pj.aura.R.id.lib_title_bar_connection_status_bad);
	}
	
	public void setState(int state) {
		if(state == CONNECTED) {
			Log.i("TitleBar", "connected");
			progressBarTitle.setVisibility(View.GONE);
			imageViewTitleGoodConnection.setVisibility(View.VISIBLE);
			imageViewTitleBadConnection.setVisibility(View.GONE);
		} else if(state == CONNECTING) {
			Log.i("TitleBar", "connecting");
			imageViewTitleGoodConnection.setVisibility(View.GONE);
			imageViewTitleBadConnection.setVisibility(View.GONE);
			progressBarTitle.setVisibility(View.VISIBLE);
		} else if(state == NOT_CONNECTED) {
			Log.i("TitleBar", "not connected");
			imageViewTitleGoodConnection.setVisibility(View.GONE);
			imageViewTitleBadConnection.setVisibility(View.VISIBLE);
			progressBarTitle.setVisibility(View.GONE);
		}
	}
	
	
}
